package com.fc.authentication.modules.member.rs;

import com.fc.authentication.common.dto.Result;
import com.fc.authentication.modules.member.domain.Member;
import com.fc.authentication.modules.member.dto.MemberCreateRequest;
import com.fc.authentication.modules.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Sunny on 2018/6/28.
 */
@RestController
@RequestMapping("/api/member")
public class MemberResource {

    @Autowired
    private MemberService memberService;

    @PostMapping
    public Result createMember(@RequestBody MemberCreateRequest memberCreateRequest)
    {
        memberService.createMember(memberCreateRequest);
        return Result.ok();
    }

    @GetMapping("/list")
    public Result list(@PageableDefault(sort = {"age"}, direction = Sort.Direction.DESC) Pageable pageable)
    {
        Page<Member> memberPage = memberService.findMemberList(pageable);
        return Result.ok(memberPage);
    }
}
